<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
		<link rel="stylesheet" href="js/Cesium/Widgets/widgets.css" />
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/Cesium/Cesium.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
		<style>
			html,body{
				margin: 0;
				padding: 0;
				height: 100%;
				width: 100%;
			}
			#contanter{
				width:100%;
				height:100%
			}    
			/* 去除logo信息 */	
			.cesium-widget-credits{ 
				display:none!important; 
				visibility:hide!important; 
			} 
		</style>
    </head>
    <body>
		<div id="contanter"></div>
		<script>
			var viewer = new Cesium.Viewer("contanter",{
					animation: false,  //是否显示动画控件
		            baseLayerPicker: false, //是否显示图层选择控件
		            geocoder: true, //是否显示地名查找控件
		            timeline: false, //是否显示时间线控件
		            sceneModePicker: true, //是否显示投影方式控件
		            navigationHelpButton: false, //是否显示帮助信息控件
		            infoBox: true,  //是否显示点击要素之后显示的信息
					// 加载地形数据
					terrainProvider: Cesium.createWorldTerrain({
						 // required for water effects
						 requestWaterMask:true, 
						 // required for terrain lighting
						 requestVertexNormals :true 
					})
			})
			
			var provider = new Cesium.WebMapServiceImageryProvider({
	              url: 'http://localhost:6080/arcgis/services/newcapec/watershed/MapServer/WMSServer',
	              layers: '0',
				  crs : 'EPSG:4326',
	              parameters: {
	              	  service : 'WMS',
	                  format: 'image/png',
	                  transparent: true,
	              }
	        });
			viewer.imageryLayers.addImageryProvider(provider);
		  
			var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

	        handler.setInputAction(function (movement) {
				var ray = viewer.camera.getPickRay(movement.position);
				var cartesian = viewer.scene.globe.pick(ray, viewer.scene);
				if (cartesian) {
					var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
					if (cartographic) {
						var xy = new Cesium.Cartesian2();
						var alti = viewer.camera.positionCartographic.height;
						var level = getLevel(alti);
						if (provider.ready) {
							xy = provider.tilingScheme.positionToTileXY(cartographic, level, xy);
							var promise = provider.pickFeatures(xy.x, xy.y, level, cartographic.longitude, cartographic.latitude);
						    Cesium.when(promise, function (data) {
							  console.log("属性数据",data)
							  if(data){
								  console.log(data[0].data.properties)
							  }
							})
						}
					}
				}
		    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
		
			function getLevel(height) {
				if (height > 48000000) {
					return 0;
				} else if (height > 24000000) {
					return 1;
				} else if (height > 12000000) {
					return 2;
				} else if (height > 6000000) {
					return 3;
				} else if (height > 3000000) {
					return 4;
				} else if (height > 1500000) {
					return 5;
				} else if (height > 750000) {
					return 6;
				} else if (height > 375000) {
					return 7;
				} else if (height > 187500) {
					return 8;
				} else if (height > 93750) {
					return 9;
				} else if (height > 46875) {
					return 10;
				} else if (height > 23437.5) {
					return 11;
				} else if (height > 11718.75) {
					return 12;
				} else if (height > 5859.38) {
					return 13;
				} else if (height > 2929.69) {
					return 14;
				} else if (height > 1464.84) {
					return 15;
				} else if (height > 732.42) {
					return 16;
				} else if (height > 366.21) {
					return 17;
				} else {
					return 18;
				}
			}
	
		  viewer.flyTo(provider);
		</script>
    </body>
</html>